const mysql = require("mysql")
const express = require("express")()
const static =  require("express-static")
const ejs = require("ejs")
const url = require("url")
const port = 8088



var sql = mysql.createConnection({
	database:"chajia",
	host:"localhost",
	user:"root",
	password:"10086"
})
sql.connect();



express.get("/",(request,response)=>{

	ejs.renderFile("yuan/chajia.html",{},(err,data)=>{
		response.end(data)
	})
})



express.get("/getData",(request,response)=>{

	sql.query(`select * from person`,(err,result)=>{
		if(err){
			console.log(err);
			response.end("err")
		}
		else{
				response.end(JSON.stringify(result))
			}
	})
})


express.get("/deleteData",(request,response)=>{
	const id = url.parse(request.url,true).query.id;
	sql.query(`delete from person where id="${id}"`,(err,result)=>{

		if(err){
				response.end("err")
				console.log("删除失败")
			}
		else{
			if(err){
				response.end("successs")
			}

			else{
				response.end("folid")
			}
		}
	})
})








express.use(static(__dirname + "/yuan"))
express.listen(port)
console.log(`port is running ${port}`)